package org.jeecg.modules.demo.com.kunpeng.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.demo.com.kunpeng.entity.CollectionRecord;
import org.jeecg.modules.demo.com.kunpeng.entity.OaFile;
import org.jeecg.modules.demo.com.kunpeng.mapper.CollectionRecordMapper;
import org.jeecg.modules.demo.com.kunpeng.mapper.OaFileMapper;
import org.jeecg.modules.demo.com.kunpeng.service.ICollectionRecordService;
import org.jeecg.modules.demo.com.kunpeng.vo.CollectionRecordQueryListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
public class CollectionRecordServiceImpl extends ServiceImpl<CollectionRecordMapper, CollectionRecord> implements ICollectionRecordService {

    @Autowired
    private CollectionRecordMapper collectionRecordMapper;

    @Autowired
    private OaFileMapper oaFileMapper;
    /**
     * 根据项目id获取项目回款记录
     * @param oid
     * @return
     */
    @Override
    public List<CollectionRecordQueryListVO> collectionRecordListByOid(Integer oid) {
        //获取回款记录列表
        List<CollectionRecordQueryListVO> collectionRecordQueryListVOList = collectionRecordMapper.collectionRecordListByOid(oid);

        //给文件集合赋值
        for(CollectionRecordQueryListVO collectionRecordQueryListVO:collectionRecordQueryListVOList){
            String fileId = collectionRecordQueryListVO.getFileId();
            String[] fileIdList = fileId.split(",");
            List<OaFile> oaFileList=new ArrayList<>();
            if(fileIdList.length>0){
                for (int i=0;i<fileIdList.length;i++){
                    if(!fileIdList[i].equals("")) {
                        OaFile oaFile = oaFileMapper.selectOaFileDetailById(Integer.parseInt(fileIdList[i]));
                        oaFileList.add(oaFile);
                    }
                }
            }
            collectionRecordQueryListVO.setOaFileList(oaFileList);
        }
        return collectionRecordQueryListVOList;
    }
}
